/// b9b.cxx -- the main program for the External Target Facility
/// Created: Dec. 13, 2024, by Asia SUN, asia.rabbit@163.com
/// Last modified: Dec. 13, 2024, by Asia SUN

#include "G4RunManager.hh"
#include "G4UItcsh.hh"
#include "FTFP_BERT.hh"
#include "G4UIterminal.hh"
#include "G4UIExecutive.hh"
#include "G4UImanager.hh"
#include "G4VisExecutive.hh"
#include "G4StepLimiterPhysics.hh"
#include "EG4DetConstruct.h"
#include "EG4ActionInit.h"
#include "EG4ROOT.h"
#include "EG4ParaManager.h"

int main(int argc, char **argv){
  if(argc < 2){
    std::cout << "Usage: ./b9b <No.OfCtrlYaml>" << std::endl;
    exit(1);
  } // end if
  EG4ParaManager::Instance()->ReadParameters(argv[1]);
  // constrct the default manager
  G4RunManager *runManager = new G4RunManager;

  // mandatory user initialization classes
  runManager->SetUserInitialization(new EG4DetConstruct());
  auto pl = new FTFP_BERT();
  pl->RegisterPhysics(new G4StepLimiterPhysics());
  runManager->SetUserInitialization(pl);
  EG4ROOT *root = new EG4ROOT(); // an interface to ROOT
  EG4ActionInit *actionInit = new EG4ActionInit(root);
  // actionInit->SetUsingGun();
  runManager->SetUserInitialization(actionInit);
  runManager->Initialize();

  G4UIsession *session = new G4UIterminal(new G4UItcsh());
  G4UImanager *uim = G4UImanager::GetUIpointer();
  uim->ApplyCommand("/control/execute batch.mac");
  // session->SessionStart();

  root->Finish();
  delete session;
  delete runManager;
  return 0;
} // end main function
